home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / MDUMP.C < prev    next >
C/C++ Source or Header  |  1991-03-22  |  7KB  |  228 lines

  1. /*  mdump.c     -- dump a Minix file system */
  2. /*  Copyright 1988,1991 Steven W. Harrold - All rights reserved. */
  3. /*  $Header: MDUMP.C_V 1.6 91/03/22 07:53:57 SWH Exp $ */
  4.  
  5. #include    <stdio.h>
  6. #include    <string.h>
  7. #include    <ctype.h>
  8. #include    <time.h>
  9. #include    "mfs.h"
  10. #include    "dev.h"
  11.  
  12. PRINT_HEX_BUF
  13. READ_BLOCK
  14. DEVINIT
  15.  
  16.  
  17. /*==================================================================*/
  18. main (argc, argv)
  19. int     argc ;
  20. char    *argv[] ;
  21. {
  22.     int     drive ;
  23.     char    drid = 'A' ;
  24.     char    *dp = DRIVES ;
  25.  
  26.     byte    buf[BLOCK_SIZE] ;
  27.     int     blkno ;
  28.     struct super_block  sblk ;
  29.     int     i, j, k, n ;
  30.     int     iblkcnt ;
  31.     int     inode_blkno ;
  32.     int     ifree, zfree ;
  33.     char    c ;
  34.     struct inode    iblk ;
  35.     struct directory    dblk, *dptr ;
  36.     int     nument ;
  37.     struct devdata *ddata ;
  38.  
  39.     printf ("**** Displays structure of a Minix file system ****\n") ;
  40.     printf ("\n") ;
  41.  
  42. /*  Does he want help?
  43.  */
  44.     if ((argc >= 2) && (argv[1][0] == '-') && (argv[1][1] == '?'))
  45.     {
  46. printf ("Copyright 1988,1991 Steven W. Harrold - All rights reserved\n") ;
  47.         printf ("Version %s\n", VERSION) ;
  48.         printf ("Usage:   %s  [drid]\n", argv[0]) ;
  49.         printf ("'drid' is a letter from the set [a-z], default: 'a'\n") ;
  50.         exit (0) ;
  51.     }
  52.  
  53. /*  Fetch the drive identifier
  54.  */
  55.     if (argc >= 2)
  56.     {
  57.         drid = toupper(argv[1][0]) ;
  58.         if ((drid < 'A') || (drid > 'Z'))
  59.             drid = 'A' ;
  60.     }
  61.     drive = strchr (dp, drid) - dp ;
  62.     ddata = devinit(drive,0) ;
  63.     if (!ddata)
  64.     {
  65.         printf ("Cannot initialize device 0x%02X, Dstatus=%d\n",
  66.                 drive, Dstatus) ;
  67.         exit (2) ;
  68.     }
  69.  
  70. /*  The boot block
  71.  */
  72.     blkno = 0 ;
  73.     read_block (buf, blkno, ddata) ;
  74.     print_hex_buf (buf, blkno, "The boot block") ;
  75.  
  76. /*  The super block
  77.  */
  78.     blkno = 1 ;
  79.     read_block (buf, blkno, ddata) ;
  80.     print_hex_buf (buf, blkno, "The super block") ;
  81.  
  82.     memcpy (&sblk, buf, sizeof(sblk)) ;
  83.     printf ("**** Super block (formatted) ****\n") ;
  84.     printf ("Number of inodes.........%9d\n",    sblk.s_ninodes      ) ;
  85.     printf ("Number of zones..........%9d\n",    sblk.s_nzones       ) ;
  86.     printf ("Num inode bitmap blocks..%9d\n",    sblk.s_imap_blocks  ) ;
  87.     printf ("Num zone bitmap blocks...%9d\n",    sblk.s_zmap_blocks  ) ;
  88.     printf ("First data zone..........%9d\n",    sblk.s_firstdatazone) ;
  89.     printf ("Log2 of zone/block sizes.%9d\n",    sblk.s_log_zone_size) ;
  90.     printf ("Maximum file size.......%10ld\n",   sblk.s_max_size     ) ;
  91.     printf ("Magic number.............   0x%04X\n", sblk.s_magic     ) ;
  92.  
  93.     if ((sblk.s_magic != SUPER_MAGIC)   ||
  94.         (sblk.s_ninodes < 1)            ||
  95.         (sblk.s_nzones < 1)             ||
  96.         (sblk.s_imap_blocks < 1)        ||
  97.         (sblk.s_zmap_blocks < 1)        )
  98.     {
  99.         printf ("++++++++++++++++++++++++++++++++++++++++++++++++\n") ;
  100.         printf ("++++++++ THIS IS NOT A PROPER SUPER BLOCK ++++++\n") ;
  101.         printf ("++++++++++++++++++++++++++++++++++++++++++++++++\n") ;
  102.     }
  103.  
  104.     printf ("\n") ;
  105.  
  106. /*  The i-node bitmap blocks
  107.  */
  108.     ifree = 0 ;
  109.     for (i=0; i<sblk.s_imap_blocks; i++)
  110.     {
  111.         blkno++ ;
  112.         read_block (buf, blkno, ddata) ;
  113.         print_hex_buf (buf, blkno, "An i-node bitmap block") ;
  114.  
  115.         for (j=0; j<BLOCK_SIZE; j++)
  116.         {
  117.             c = buf[j] ;
  118.             if (!(c & 0x01)) ifree++ ;
  119.             if (!(c & 0x02)) ifree++ ;
  120.             if (!(c & 0x04)) ifree++ ;
  121.             if (!(c & 0x08)) ifree++ ;
  122.             if (!(c & 0x10)) ifree++ ;
  123.             if (!(c & 0x20)) ifree++ ;
  124.             if (!(c & 0x40)) ifree++ ;
  125.             if (!(c & 0x80)) ifree++ ;
  126.         }
  127.     }
  128.  
  129.     printf ("**** I-node bitmap summary ****\n") ;
  130.     printf ("Bitmap blocks    : %5d\n", sblk.s_imap_blocks) ;
  131.     printf ("I-nodes available: %5d\n", ifree) ;
  132.     printf ("Out of a possible: %5d\n", sblk.s_ninodes) ;
  133.     printf ("\n") ;
  134.  
  135. /*  The zone bitmap blocks
  136.  */
  137.     zfree = 0 ;
  138.     for (i=0; i<sblk.s_zmap_blocks; i++)
  139.     {
  140.         blkno++ ;
  141.         read_block (buf, blkno, ddata) ;
  142.         print_hex_buf (buf, blkno, "A zone bitmap block") ;
  143.  
  144.         for (j=0; j<BLOCK_SIZE; j++)
  145.         {
  146.             c = buf[j] ;
  147.             if (!(c & 0x01)) zfree++ ;
  148.             if (!(c & 0x02)) zfree++ ;
  149.             if (!(c & 0x04)) zfree++ ;
  150.             if (!(c & 0x08)) zfree++ ;
  151.             if (!(c & 0x10)) zfree++ ;
  152.             if (!(c & 0x20)) zfree++ ;
  153.             if (!(c & 0x40)) zfree++ ;
  154.             if (!(c & 0x80)) zfree++ ;
  155.         }
  156.     }
  157.  
  158.     printf ("**** Zone bitmap summary ****\n") ;
  159.     printf ("Bitmap blocks    : %5d\n", sblk.s_zmap_blocks) ;
  160.     printf ("Zones available  : %5d\n", zfree) ;
  161.     printf ("Out of a possible: %5d\n", sblk.s_nzones) ;
  162.     printf ("\n") ;
  163.  
  164. /*  The i-node blocks
  165.  */
  166.     inode_blkno = blkno + 1 ;
  167.     iblkcnt = sblk.s_ninodes * sizeof(struct inode) + (BLOCK_SIZE-1) ;
  168.     iblkcnt /= BLOCK_SIZE ;
  169.     for (i=0; i<iblkcnt; i++)
  170.     {
  171.         blkno++ ;
  172.         read_block (buf, blkno, ddata) ;
  173.         print_hex_buf (buf, blkno, "An i-node block") ;
  174.     }
  175.  
  176.     printf ("**** I-node summary ****\n") ;
  177.     printf ("I-node blocks: %5d\n", iblkcnt) ;
  178.     printf ("\n") ;
  179.  
  180. /*  The root directory
  181.  */
  182.     blkno = inode_blkno ;
  183.     read_block (buf, blkno, ddata) ;
  184.  
  185.     memcpy (&iblk, buf, sizeof(iblk)) ;
  186.     printf ("**** Root directory inode data (formatted) ***\n") ;
  187.     printf ("Mode...........%06o\n",  iblk.i_mode   ) ;
  188.     printf ("Owner code.....%6d\n",   iblk.i_uid    ) ;
  189.     printf ("File size...%9ld\n",     iblk.i_size   ) ;
  190.     printf ("Last modified..%s",      ctime((long *)&iblk.i_modtime));
  191.     printf ("Group code.....%6d\n",   iblk.i_gid    ) ;
  192.     printf ("Links..........%6d\n",   iblk.i_nlinks ) ;
  193.     for( i = 0; i < ZONE_SIZE; i++ )
  194.         printf( "Zone %1d pointer.%6d\n", i, iblk.i_zone[i] );
  195.     printf ("Indirect zone..%6d\n",   iblk.i_ind    ) ;
  196.     printf ("Double indirect%6d\n",   iblk.i_dbl_ind) ;
  197.     printf ("\n") ;
  198.  
  199.     for (i=0; i < ZONE_SIZE; i++)
  200.     {
  201.         if ((blkno = iblk.i_zone[i])) /*assignok*/
  202.         {
  203.             read_block (buf, blkno, ddata) ;
  204.             print_hex_buf (buf, blkno, "A root directory block") ;
  205.  
  206.             printf ("**** Root directory and inode data (formatted) ****\n") ;
  207.             nument = iblk.i_size / sizeof(dblk) ;
  208.             dptr = (struct directory *)buf ;
  209.             for (i=0; i<nument; i++)
  210.             {
  211.                 if (n = dptr[i].d_inum) /*assignok*/
  212.                 {
  213.                     printf ("inode=%5d  fname=", n) ;
  214.                     for (j=0; (j<NAME_SIZE) && (c=dptr[i].d_name[j]);
  215.                               j++)              /*assignok*/
  216.                         printf ("%c", c) ;
  217.                     printf ("\n") ;
  218.                 }
  219.             }
  220.             printf ("\n") ;
  221.         }
  222.     }
  223.  
  224. } /* main() */
  225.  
  226.  
  227. /*---eof---*/
  228.